<template>
  <el-table :data="courses" style="width: 100%">
    <el-table-column label="编号" prop="id" />
    <el-table-column label="名称" prop="name" />
    <el-table-column label="学时" prop="time" />
    <el-table-column label="学分" prop="point" />
    <el-table-column align="right">
      <template #header>
        <el-input v-model="keyword" size="small" placeholder="搜索课程" />
      </template>
      <template #default="scope">
        <el-button size="small" @click="editCourse(scope.row)">
          更新
        </el-button>
        <el-button
            size="small"
            type="danger"
        >
          删除
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <!-- 分页-->
  <el-pagination background layout="prev, pager, next" :total="total"
                 :page-size="pageSize" @current-change="loadCourse"/>
  <!-- 对话框-->
  <el-dialog v-model="dialogFormVisible" title="课程信息" width="500">
    <el-form :model="course">
      <el-form-item label="名称">
        <el-input v-model="course.name" autocomplete="off" />
      </el-form-item>
      <el-form-item label="学时">
        <el-input v-model="course.gender" autocomplete="off" />
      </el-form-item>
      <el-form-item label="学分">
        <el-input v-model="course.age" autocomplete="off" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible = false">Cancel</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">
          Confirm
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
export default {
  name: "CourseView",
  data() {
    return {
      courses: [],
      keyword: '',
      current: 1,
      pageSize: 10,
      total: 10,
      dialogFormVisible: false,
      course: {}
    }
  },
  methods: {
    loadCourse(current) {
      this.current = current
      this.$axios.get('/findCoursePage?current=' + this.current + "&pageSize=" + this.pageSize)
          .then(result => {
            console.log('course', result.data)
            if (result.data.code === 200) {
              this.courses = result.data.data.data;
              this.total = result.data.data.total;
            }
          })
    },
    //编辑学生
    editCourse(cou){
      //显示对话框
      this.dialogFormVisible = true;
      //显示学生信息
      this.course = JSON.parse(JSON.stringify(cou));
    }
  },
    mounted() {
      this.loadCourse(1)
    }
}
</script>

<style scoped>

</style>